package com.example.llh.zyfypt_110llh.activity;

import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.llh.zyfypt_110llh.R;
import com.example.llh.zyfypt_110llh.iface.register.RegisterListener;
import com.example.llh.zyfypt_110llh.model.register.RegisterModel;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener,RegisterListener{

    private EditText user,password,againpwd,name,tel;
    private Button photograph,register,returnlogin;
    private RegisterModel registerModel;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        init();
        toolBarInit();
    }

    private void toolBarInit() {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_register);
        setSupportActionBar(toolbar);

        ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle("注册界面");
    }
    private void init(){
        user=(EditText)findViewById(R.id.editText_username);
        password=(EditText)findViewById(R.id.editText_pass);
        againpwd=(EditText)findViewById(R.id.editText6);
        name=(EditText)findViewById(R.id.editText7);
        tel=(EditText)findViewById(R.id.editText_tel);
        photograph=(Button)findViewById(R.id.button_photograph);
        register=(Button)findViewById(R.id.button_reg);
        returnlogin=(Button)findViewById(R.id.button5);

        returnlogin.setOnClickListener(this);
        register.setOnClickListener(this);
        photograph.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button_reg:
                registerModel=new RegisterModel();
                registerModel.getResultList(user.getText().toString(),password.getText().toString(),tel.getText().toString(),this);
                break;
            case R.id.button5:
                Intent intent=new Intent(RegisterActivity.this,LoginActivity.class);
                startActivity(intent);
                break;
        }
    }

    @Override
    public void onResponse(String str) {
        if(str.equals("1")){
            Toast.makeText(this,"注册成功", Toast.LENGTH_SHORT).show();
            Intent intent1=new Intent(RegisterActivity.this,LoginActivity.class);
            startActivity(intent1);
        }else{
            Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onFail(String msg) {

    }

}
